# syntax=docker/dockerfile:1

# -------- builder stage --------
FROM public.ecr.aws/docker/library/debian:bookworm-slim AS builder

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       build-essential \
       ca-certificates \
       git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /src

# Copy source
COPY . /src

# Build predixy binary. Force dynamic libstdc++ link to avoid missing -lstdc++ in slim images.
# Output binary is at src/predixy
RUN cd src \
    && make clean || true \
    && make -e LDLIBCPP= LDFLAGS='-rdynamic -lpthread'

# -------- runtime stage --------
FROM public.ecr.aws/docker/library/debian:bookworm-slim

ENV DEBIAN_FRONTEND=noninteractive

# Minimal runtime deps
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && useradd -r -s /usr/sbin/nologin predixy

WORKDIR /app

# Copy binary
COPY --from=builder /src/src/predixy /usr/local/bin/predixy

# Copy default configs
COPY conf /etc/predixy

# Listen port; default is 7617 per conf/predixy.conf
EXPOSE 7617/tcp

USER predixy

# Use the bundled example config by default; can be overridden at runtime
CMD ["/usr/local/bin/predixy", "/etc/predixy/predixy.conf"]
